<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>{$user.qudao_id|re_qudao_nick_name}</title>

  <script src="https://cdn.jsdelivr.net/npm/babel-polyfill/dist/polyfill.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/jquery"></script>
  <script src="__PUBLIC__/script/common.js" common-data-1="{:U('Mix/dest')}"></script>
  <script src="__PUBLIC__/script/jquery-weui/dist/js/jquery-weui.min.js"></script>
  <script src="__PUBLIC__/script/diqu_weixin.js?v=1.0.0"></script>
  <link rel="stylesheet" href="__PUBLIC__/script/jquery-weui/dist/lib/weui.min.css">
  <link rel="stylesheet" href="__PUBLIC__/script/jquery-weui/dist/css/jquery-weui.min.css">
  <link rel="stylesheet" href="__PUBLIC__/styles/base.css">
  <link rel="stylesheet" href="__PUBLIC__/styles/diqu_weixin.css">
  <link rel="stylesheet" href="__PUBLIC__/styles/font/iconfont.css">
</head>
<body>
  <!-- 不显示的内容 -->
  <div style="display:none;">
    <input type="hidden" name="修改产品信息" id='modifyURL' value="{:U('Home/Index/send_msg')}">
    <input type="hidden" name="获取 用户联系列表" id='getList' value="{:U('WebUser/ajax_re_chat')}">
    <input type="hidden" name="进入聊天室" id='enterRoom' value="{:U('Chat/qudao_chat')}">
  </div>
<!--   <script>
  // /* 后端调试去掉 */
  $('pre').each((index, item) => {$(item).remove()})
</script> -->
  <div class="container">
    <div class="header">{$user.qudao_id|re_qudao_nick_name}</div>
    <div class="message_box">

      <!-- 个人信息 -->
      <div class="me">
        <div class="renshu float_left">
          <div class="name">{$user.web_name}</div>
          <div class="location">{$user.web_pro_id|re_region_address}{$user.web_city_id|re_region_address}{$user.web_area_id|re_region_address}</div>
          <div class="phone">{$user.web_phone}</div>
        </div>
        <div class="logo float_left">
          <img src="{$headimgurl}" alt="logo">
        </div>
        <div class="need_more float_left">
          <div class="kefu" inori-href="{:U('Wchat/huoquyaoqin')}">评估令客服</div>
          <div class="chanpin_modify"><a href="javascript:void(0);" class="open-popup" data-target="#modify_chanpin_popup">产品更改</a></div>
        </div>
        <div class="float_clear"></div>
      </div>

      <div style='background-color:#EAEFF5;height: 1vh'></div>
    </div>
  </div>

  <!-- 主要内容 -->
  <!-- 一个产品一个pro_card -->
  <volist name='goods' id='vo'>
  <div class="weui-cells pro_card">
    <div class="weui-cell">
        <!-- <div class="weui-flex__item pro_uid" inori-data='{$vo.id}'></div> -->
        <div class="weui-flex__item pro_uid" p-id='{$vo.id}' x-id='{$vo.id|fun_nick_name}' inori-data='{$vo.id}'>{$vo.id|re_letter_name}</div>
    </div>
    <div class="weui-cell pro_title">
      <div class="weui-flex__item pro_edu">{$vo.my_lx_data.min_ed}万~{$vo.my_lx_data.max_ed}万</div>
      <div class="weui-flex__item pro_lixi">{$vo.my_lx_data.min_lx}%~{$vo.my_lx_data.max_lx}%<span>(等额本息)</span></div>
      <div class="weui-flex__item pro_fenqi">{$vo.my_lx_data.installment_fq}期</div>
    </div>
    <div class="weui-cell pro_tag">
      <div class="tag weui-flex__item">{$vo.dtypename|qudao_type}</div>
      <div class="tag weui-flex__item"><volist name='vo.cp_temp' id='val'>{$val.name}</volist></div>
      <if condition='$vo.goods_diy_name_id neq null'>
      <div class="ad ad_main weui-flex__item">评估令推荐</div>
      </if>
<!--       <div class="ad ad_alt weui-flex__item">999位推荐</div>
 -->    </div>
    <div class="weui-cell pro_adv">
      <div class="weui-flex__item">{$vo.letterzhengxin}</div>
      <div class="weui-flex__item">{$vo.my_lx_data.fangkuan_time}天放款</div>
      <div class="weui-flex__item">手续费{$vo.my_lx_data.handling}%</div>
      <!-- 点击时JS remove 掉 unread 这个class -->
      <div class="weui-flex__item btn"><label for = "uidAA{$vo.id}" class="weui-btn weui-btn_mini weui-btn_default getList">最近咨询</label></div>
    </div>
    <div class="weui-cell pro_qudao">
      <input type="radio" name='不提交的按钮，指示折叠用' form='not_submit' id='uidAA{$vo.id}' class="chanpin_type_hidden_checkbox">
      <div class="weui-cells pro_qudao_wrap pro_qudao_wrap_1">
        <div class="pro_qudao_title weui-flex">
          <div class="yewu_person weui-flex__item">咨询人</div>
          <div class="vip_edu weui-flex__item">客户需求</div>
          <div class="anjie_person weui-flex__item"><a>按揭员</a></div>
          <div class="time_avg weui-flex__item">咨询日期</div>
          <div class="unreadif unread"></div>
          <div class="more">
            <i class="iconfont">&#xe6a7;</i>
          </div>
        </div>
        <div class="sub_card_qudao">
          <div class="sub_card_qudao_item weui-flex" inori-href='null'>
            <div class="yewu_person weui-flex__item"></div>
            <div class="vip_edu weui-flex__item"></div>
            <div class="anjie_person weui-flex__item"><a href="tel:15617715148;"></a></div>
            <div class="time_avg weui-flex__item"></div>
            <div class="unreadif unread"></div>
            <div class="more">
              <i class="iconfont">&#xe6a7;</i>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  </volist>


    <!-- end 主要内容 -->
    <!-- 弹层 修改产品 -->
    <div id="modify_chanpin_popup" class="weui-popup__container popup-bottom">
      <div class="weui-popup__overlay"></div>
      <div class="weui-popup__modal">
        <div class="toolbar">
          <div class="toolbar-inner">
            <h1 class="js-modify_loca" style="position: absolute;display: block;padding: 0;font-weight: 400;line-height: 2.2rem;text-align: center;white-space: nowrap; font-size: 10px;left: 15px;">{$user.qudao_id|re_qudao_nick_name}</h1>
            <h1 class="js-modify_person" style="position: absolute;display: block;padding: 0;font-weight: 400;line-height: 2.2rem;text-align: center;white-space: nowrap; font-size: 10px;right: 15px;">{$user.web_name}/{$user.web_phone}</h1>
          </div>
        </div>
        <div class="modal-content">
          <div class="textarea_wrap">
            <textarea name="modify_textarea" id="modify_textarea" placeholder="请告诉我们产品有什么错误或更改，会有红包哦！"></textarea>
          </div>
          <div class="btn_wrap">
            <!-- 不要修改这里的超链接，提交链接书写在页面头部的 input:hidden 区域 -->
            <a href="javascript:;" class="weui-btn weui-btn_plain-primary" style="color: #007cb8;border-color: #007cb8;" onclick="postThisModify(this, event)">确定</a>
            <a href="javascript:;" class="weui-btn weui-btn_plain-default close-popup">取消</a>
          </div>
        </div>
      </div>
    </div>
    <!-- end 弹层 修改产品 -->

  <!-- 跳转 -->
  <script>
    $(document).ready(() => {
      $('.kefu').on('click', (evt) => {
        evt.preventDefault()
        $.each($('.pro_adv .weui-btn_mini'), (index, item) => {
          $(`#${$(item).attr('for')}`).prop('checked', false).change()
          $(item).removeClass('active')
        })
        debugger
        setTimeout(() => {
          location.href = `${$(evt.target).attr('inori-href')}${$(evt.target).attr('inori-href').match(/\\?/) ? '&' : '?'}front_end_not_submit=${Math.random()}`
        }, 0)
      })
      // $('.chanpin_modify').on('click', (evt) => {
      //   location.href = `${$(evt.target).attr('inori-href')}?front_end_not_submit=${Math.random()}`
      // })
    })
  </script>
  <!-- 产品修改 -->
  <script>
    function postThisModify (_this, evt) {
      const parentEle = $(evt.target).closest('modal-content')
      const ajaxURL = String($('#modifyURL').val())
      const ajaxData = {
        msg: `
          更改提交人所属渠道：${$('.js-modify_loca').text()}<br />
          提交人基础信息：${$('.js-modify_person').text()}<br />
          修改提议：<br />
          <hr />
          　${String($(`#modify_textarea`).val()).replace(/[\r(\r\n)]/g, `<br />`)}<br />
        `
      }
      $.ajax(ajaxURL, {
        method: 'post',
        data: ajaxData,
        beforeSend: () => {
          $.toptip(`正在提交数据`, 'success')
        }
      }).fail((err) => {
        $.toptip(`提交数据失败！请检查网络后重试`, 'error')
        throw err
      }).done((res) => {
        if(res.code && String(res.code) !== '1') {
          $.toptip(`提交数据失败！服务器返回异常111: ${res.message}`, 'error')
          throw err
        }
        if(!res.code && `${res}`.match(/\d{1,}/) && isNaN(Number(`${res}`.match(/\d{1,}/)[0]))) {
          $.toptip(`提交数据失败！服务器返回异常: ${res}`, 'error')
          throw err
        }
      }).done((res) => {
        $.toptip(`提交数据成功！`, 'success')
        // 清空对话框
        $(`#modify_textarea`).val(null)
        // 关闭弹窗
        $('.close-popup').click()

      })
    }
  </script>
  <!-- 循环截断 -->
  <script>
    $(document).ready(() => {
      $('.yewu_person ').each((index, item) => {
        if ($(item).text().length > 4) {
          const viewText = `$(item).text().substr(0, 3)...`
          $(item).text()
        }
      })
    })
  </script>
  <!-- 获取聊天列表 -->
  <script>
    $('.getList').each((index, item) => {
      $(item).on('click', (evt) => {
        const parentCard = $(evt.target).closest('.pro_card')
        const goodID = parentCard.find('.pro_uid').attr('inori-data')
        // 先清空
        parentCard.find('.sub_card_qudao').empty()
        const ajaxURL = $('#getList').val()
        const ajaxData = {
          goods_id: goodID
        }
        // 判断是不是已经展开
        if ($(evt.target).closest('.getList').hasClass('active')) {
          // 如果已经展开就return，交给下一个事件handler,去除active并反check
          return
        }
        evt.preventDefault()
        $.ajax(`${ajaxURL}`, {
          method: 'post',
          data: ajaxData,
          beforeSend: () => {
            $.toptip(`正在获取聊天列表`, 'success')
          }
        }).fail((err) => {
          $.toptip(`获取聊天列表失败，请检查网络后重试`, 'error')
          throw err
        }).done((res) => {
          if (!res.code) {
            $.toptip(`服务器响应失败`, 'error')
            throw new Error(`服务器响应失败: ${JSON.stringify(res)}`)
          }
          if (res.code && (String(res.code) !== '1' && String(res.code) !== '2')) {
            $.toptip(`服务器响应失败: ${res.message}`, 'error')
            throw new Error(`服务器响应失败: ${JSON.stringify(res)}`)
          }
          if (res.code && String(res.code) === '2') {
            $.toptip(`${res.message}`, 'warning')
            throw new Error(`${JSON.stringify(res)}`)
          }
        }).done((res) => {
          const resData = res.data
          let listTempl = ``
          $.each(resData, (index, item) => {
            /**
             * $chat_id=I('get.chat_id');
             * $web_id=I('get.web_id');
             * $goods_id=I('get.goods_id');
             * $f_web_id=I('get.');
             * $from_user_group_id=I('get.from_user_group_id');//业务员发送消息id
            */
            const cg_id = item.cg_id
            const chat_id = item.chat_id
            const from_user_group = item.from_user_group
            const from_user_group_id = item.from_user_group_id
            const goods_id = item.goods_id
            const y_id = item.y_id
            const kehu_name = item.kehu_name
            let kehu_data = item.data
            const init_time = item.time.match(/\d\d\d\d年\d\d月\d\d日/)[0].replace(/年/,'/').replace(/月/,'/').replace(/日/,'')
            const aj_data = item.aj_data
            if (!cg_id || !chat_id || !from_user_group || !from_user_group_id || !goods_id || !y_id || !kehu_name || !kehu_data || !init_time || !aj_data) {
              // 跳过该次循环，不能丢error,
              return
            }
            const aj_name = aj_data.web_name
            const aj_phone = aj_data.web_phone
            const hrefBase = String($('#enterRoom').val())
            const inoriHref = `${hrefBase}?chat_id=${chat_id}&web_id=${y_id}&goods_id=${goods_id}&from_user_group_id=${from_user_group_id}`
            // 解析客户资料，JSON数据
            let kehu_edu = 0
            try {
              kehu_data = JSON.parse(kehu_data)
              $.each(kehu_data, (index, item) => {if(item.name === 'kehu_edu') kehu_edu = item.value})
              // for(let item of kehu_data) {
              //   if(item.name === 'kehu_edu') kehu_edu = item.value
              // }
            } catch (err) {
              console.log(err)
              // 跳过该次循环，不能丢error,
              return
            }
            const templ = `
              <div class="sub_card_qudao_item weui-flex" inori-href='${inoriHref}'>
                <div class="yewu_person weui-flex__item">${kehu_name}</div>
                <div class="vip_edu weui-flex__item">${kehu_edu}万</div>
                <div class="anjie_person weui-flex__item"><a href="tel:${aj_phone}">${aj_name}</a></div>
                <div class="time_avg weui-flex__item">${init_time}</div>
                <div class="unreadif"></div>
                <div class="more">
                  <i class="iconfont">&#xe6a7;</i>
                </div>
              </div>
            `.trim()
            listTempl += templ
          })
          parentCard.find('.sub_card_qudao').empty()
          parentCard.find('.sub_card_qudao').append(listTempl)
          const targetInput = $(`#${$(evt.target).attr('for')}`)
          targetInput.prop('checked', true)
          targetInput.change()
        }).done((res) => {
          if (parentCard.find('.sub_card_qudao_item').length === 0) {
            $.toptip('没有聊天数据', 'warning')
            return
          }
          // 挂事件，进入聊天室
          parentCard.find('.sub_card_qudao_item').each((index, item) => {
            $(item).on('click', (subevt) => {
              evt.preventDefault()
              $.each($('.pro_adv .weui-btn_mini'), (index, item) => {
                $(`#${$(item).attr('for')}`).prop('checked', false).change()
                $(item).removeClass('active')
              })
              debugger
              setTimeout(() => {
                const url = $(subevt.target).closest('.sub_card_qudao_item').attr('inori-href')
                location.href = url
              }, 0)
            })
          })
          $.toptip('完成操作，可以查看并进入聊天室', 'success')
        })
      })
    })
  </script>
  <!-- 不允许后退 -->
  <script>
    // 防止页面后退
    // 页面载入时使用pushState插入一条历史记录
    history.pushState(null, null, location.href.replace(/[\&\?]+front_end_not_submit.+/, '') + "" + location.href.match(/\?/) ? '&' : '?' + "front_end_not_submit=" + Math.random());
    sessionStorage.setItem('local', location.href.replace(/[\&\?]+front_end_not_submit.+/, ''))
    console.log('刷新');
    window.addEventListener('popstate', function(event) {
        console.log('回退');
        // 点击回退时再向历史记录插入一条，以便阻止下一次点击回退
        history.pushState(null, null, sessionStorage.getItem('local') + "?front_end_not_submit=" + Math.random());
    })




  </script>

</body>
</html>